package com.shc.community;

import com.shc.community.dao.DiscussPostMapper;
import com.shc.community.dao.UserMapper;
import com.shc.community.entity.DiscussPost;
import com.shc.community.entity.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;

import java.util.Date;
import java.util.List;

@SpringBootTest
@ContextConfiguration(classes = CommunityApplication.class)
public class TextApplication {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private DiscussPostMapper discussPostMapper;

    @Test
    public void findById(){
        User user = userMapper.findById(1);
        System.out.println(user);

        User user1 = userMapper.fingByName("SYSTEM");
        System.out.println(user1);

        User user2 = userMapper.findByEmail("nowcoder1@sina.com");
        System.out.println(user2);
    }

    @Test
    public void insertUser(){
        User user = new User();
        user.setUsername("test");
        user.setPassword("123456");
        user.setEmail("text@qq.com");
        user.setCreateTime(new Date());
        user.setHeaderUrl("http://www.aasdasd.com/101.png");
        user.setSalt("abc");
        int rows = userMapper.addUser(user);
        System.out.println(rows);
    }

    @Test
    public void updateUser(){
        int rows = userMapper.updateHeader(150, "http://www.aasdasd.com/102.png");
        System.out.println(rows);
        int rows1 = userMapper.updatePassword(150, "654321");
        System.out.println(rows1);
        int rows2 = userMapper.updateStatus(150, 1);
        System.out.println(rows2);

    }
    @Test
    public void testFindPosts(){
        List<DiscussPost> l = discussPostMapper.findDiscussPosts(0, 0, 20);
        for (DiscussPost discussPost : l) {
            System.out.println(discussPost);
        }
    }
}
